package 力扣.二叉树相关问题.中度题;

import java.util.HashSet;
import java.util.Set;

public class 重新规划路线 {

    public int minReorder(int n, int[][] connections) {
        if (n<=1)
            return 0;
        int count=0;
       Set<Integer> set = new HashSet<>();
       set.add(0);
       while (set.size()!=n){
           for (int[] connection : connections) {
               if (set.contains(connection[1]))
                   set.add(connection[0]);
               else if (set.contains(connection[0])){
                   count++;
                   set.add(connection[1]);
               }
           }
       }
       return count;
    }
}
